package com.vueblog.webapi.request;

import com.sun.istack.internal.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Min;

/**
 * <p>
 * 分页 请求参数
 * </p>
 *
 * @author intest
 * @since 2019-07-22
 */
@Data
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
public class BasePageRequest {

    /**
     * 页码
     */
    @NotNull
    @Min(value = 1)
    private Integer pageNum;

    /**
     * 每页条数
     */
    @NotNull
    @Min(value = 1)
    private Integer pageSize;

    /**
     * 排序字段
     */
    private String orderField;

    /**
     * 排序方向
     */
    private String direction;

    public void setOrderField(String value) {
        this.orderField = getOrderKey(value);
    }

    public void setDirection(String value) {
        String asc = "asc";
        if (asc.equals(value)) {
            this.direction = asc;
        } else {
            this.direction = "desc";
        }
    }

    public String getOrderKey(String value) {
        return value;
    }
}
